var nav_bar_path = getLastScriptPath();
$(document).on("pagebeforecreate", function (event) {
	loadNavBar()
});

function loadNavBar() {
	var nav_bar_div = $("div[data-role='footer']");
	nav_bar_div.attr('data-position', 'fixed');
	nav_bar_div.attr('data-tap-toggle', 'false');
	nav_bar_div.load(nav_bar_path + '/nav_bar.html', function () {
		var home_ul = $('#home_ul');
		var home_nav_array_i = home_ul.find('i');
		var home_nav_array_li = home_ul.find('li');
		var nav_background_click = [
			'../component/img/nav_home01.png',
			'../component/img/nav_home02.png',
			'../component/img/nav_home03.png',
			'../component/img/nav_home04.png',
			'../component/img/nav_home05.png'];
		var nav_background = [
			'../component/img/nav_home1.png',
			'../component/img/nav_home2.png',
			'../component/img/nav_home3.png',
			'../component/img/nav_home4.png',
			'../component/img/nav_home5.png'];

		for (var k = 0; k < home_nav_array_i.length; k++) {
			home_nav_array_i[k].style.backgroundImage = 'url(' + nav_background[k] + ')';
		}
		for (var i = 0; i < home_nav_array_li.length; i++) {
			home_nav_array_li[i].z = i;
			home_nav_array_li[i].onclick = function () {
				home_nav_array_i[this.z].style.backgroundImage = 'url(' + nav_background_click[this.z] + ')';
				for (var j = 0; j < home_nav_array_i.length; j++) {
					if (j != this.z) {
						home_nav_array_i[j].style.backgroundImage = 'url(' + nav_background[j] + ')';
					}
				}
			}
		}
		$("  #home_ul li").click(function () {
			$("  #home_nav li a").css({
				color: "black"
			});
			$(this).children('a').css({
				color: "#59bd9b"
			})
		});
		$('#shopHomeLink').on('tap', function () {
			navToPage(navBarIndex.shop);
		});

		$('#productHomeLink').on('tap', function () {
			navToPage(navBarIndex.home);
		});

		$('#categoryHomeLink').on('tap', function () {
			navToPage(navBarIndex.category);
		});
		$("#cartHomeLink").on('tap',function(){
			navToPage(navBarIndex.shop_detail);
		});
		$("#mineHomeLink").on('tap',function(){
			navToPage(navBarIndex.promotion);
		})
	})
}


